package com.ronan.imserver.handler;


import com.ronan.common.codec.RIMFrameDecoder;
import com.ronan.common.codec.RIMProtocolDecoder;
import com.ronan.common.codec.RIMProtocolEncoder;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;

/**
 * FileName    : com.ronan.imserver.handler
 * Description :
 *
 * @author : ysk
 * @version : 1.0
 * Create Date : 2021/2/25 23:51
 **/
public class RIMHandlerInitializer extends ChannelInitializer<SocketChannel> {

    @Override
    protected void initChannel(SocketChannel ch) throws Exception {
        ChannelPipeline pipeline = ch.pipeline();

        // 一次编码
        pipeline.addLast("LengthFieldBasedFrameDecoder", new RIMFrameDecoder());

        // 二次编码
        pipeline.addLast("decode", new RIMProtocolDecoder());
        pipeline.addLast("encode", new RIMProtocolEncoder());

        // 5秒没有向客户端发送消息就发生心跳
        // pipeline.addLast("ping", new IdleStateHandler(5, 0, 0, TimeUnit.SECONDS));

        // 业务 handler
        pipeline.addLast("biz", new RIMBizHandler());

    }
}
